package com.z.blog.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.z.blog.entity.Tag;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

/**
 * 博客标签Mapper接口
 *
 * @author z
 * @date 2022-08-29
 */
@Mapper
public interface TagMapper extends BaseMapper<Tag> {
    /**
     * 查询博客标签列表
     *
     * @param tag 博客标签
     * @return 博客标签集合
     */
    List<Tag> selectTagList(Tag tag);

    /**
     * 查询博客标签列表
     *
     * @param blogId 博客id
     * @return 博客标签集合
     */
    List<Tag> selectTagsByBlogId(Long blogId);

    @Select("select tags_id from t_blog_tags where blogs_id = #{blogId}")
    List<Integer> getIdsByBlogId(Long id);

    @Delete("delete from t_blog_tags where blogs_id =#{blogId}")
    void deleteCenterTagIdsByBlogId(Long blogId);

    @Insert("insert into t_blog_tags (blogs_id, tags_id) values (#{blogId}, #{tagId})")
    void insertCenterTagId(Long tagId, Long blogId);

    void deleteCenterTagIdsByBlogIds(Collection<?> list);
    @Select("select * from t_tag where id in(select tags_id from t_blog_tags where blogs_id = #{blogId})")
    List<Tag> getTagsByBlogId(Long id);
}
